package com.coocaa.x.service.litecontent.providers;

/**
 * Created by admin on 2015/7/28.
 */
public abstract class DataResolver<E, T> {

    public static class NoDataException extends Exception {

        public NoDataException(String detailMessage) {
            super(detailMessage);
        }
    }

    protected abstract E getDataFromCache(T t);

    protected abstract void updateCache(T t, E data);

    protected abstract E getDataFromOriginal(T t);

    public synchronized E getData(T t) {
        E ret = null;
        ret = getDataFromCache(t);
        if (ret != null)
            return ret;
        ret = getDataFromOriginal(t);
        if (ret != null)
            updateCache(t, ret);
        return ret;
    }
}
